namespace designpatternsplusplus.decorator.DecoratorParticipants
{
    #region

    using designpatternsplus.contracts;

    #endregion

    /// <summary>
    /// Our single concrete item we can then decorate with
    /// tax calculations. This is a tangible good
    /// for sale
    /// 
    /// Single Responsibility: Simply represents details
    /// about an item about to be sold (but it does not
    /// have to be... The customer could return it
    /// to the shelf). Data focused and delegates most to 
    /// a wrapped instance from our repository for the item
    /// </summary>
    public sealed class SellableItem : IProductService
    {
        readonly ISkuDetails _skuDetails;

        /// <summary>
        /// Initializes a new instance of the <see cref="SellableItem"/> class.
        /// We use the product fact instance from the master
        /// repository to init
        /// </summary>
        /// <param name="resolveSku">The resolve product.</param>
        public SellableItem(ISkuDetails resolveSku)
        {
            _skuDetails = resolveSku;
        }

        /// <summary>
        /// Gets a value indicating whether this instance is tax exempt.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is tax exempt; otherwise, <c>false</c>.
        /// </value>
        public bool IsTaxExempt
        {
            get { return _skuDetails.Type.IsTaxExempt; }
        }

        #region IProductService Members

        public ProductType Type
        {
            get { return _skuDetails.Type; }
        }

        /// <summary>
        /// Gets or sets the quantity.
        /// This is determinant from the instance
        /// where the others are lookup
        /// data
        /// </summary>
        /// <value>The quantity.</value>
        public int Quantity { get; set; }

        /// <summary>
        /// Gets a value indicating whether this instance is imported.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is imported; otherwise, <c>false</c>.
        /// </value>
        public bool IsImported
        {
            get { return _skuDetails.IsImported; }
        }

        /// <summary>
        /// Gets the sku (Unique ID) for the item
        /// </summary>
        /// <value>The sku.</value>
        public string Sku
        {
            get { return _skuDetails.Sku; }
        }

        /// <summary>
        /// Gets the master fact sheet wich is 
        /// immutable - mostly for regression
        /// or showing to a manager for
        /// price lookups
        /// </summary>
        /// <value>The master facts.</value>
        public ISkuDetails MasterDetails
        {
            get { return _skuDetails; }
        }

        /// <summary>
        /// Gets the amount at the product level
        /// </summary>
        /// <returns></returns>
        public double Amount()
        {
            return _skuDetails.RetailPrice;
        }

        /// <summary>
        /// Gets the shelf amount 
        /// (pre-tax amount)
        /// </summary>
        /// <value>The shelf amount.</value>
        public double BaseAmount
        {
            get { return _skuDetails.RetailPrice; }
        }

        #endregion
    }
}